package com.ssu.sslab;
import java.io.IOException;
import java.net.*;
import java.util.ArrayList;

import com.ssu.sslab.restriction.DataType;
import com.ssu.sslab.restriction.InfoType;
import com.ssu.sslab.sensorInfo.SensorsInfo;


/**
 * The Server has many Clients to conntect.
 * @author chengqiang sun
 *
 */
public class SensingServerStarter implements DataType {
	
	private static final int PORT = 9797;
	private static ServerSocket ss;
	
	public static void main(String [] args) {
		
		try {
			ss = new ServerSocket(PORT);
			
			System.out.println("Server is ready!");
			System.out.println("The Server is waitting for connectting:....");
			Socket socket = null;
			
			
			SensorsInfo s1 = new SensorsInfo(1123, "Touch",InfoType.BOOLEAN, true, "Test touch.");
			SensorsInfo s2 = new SensorsInfo(156, "Ultra", InfoType.INT, 120, "Test Ultra");
			SensorsInfo s3 = new SensorsInfo(2451, "Light", InfoType.FLOAT, 2.32, "Test light");
			
			ArrayList< SensorsInfo > sensorsInfos = new ArrayList<>();
			sensorsInfos.add(s1);
			sensorsInfos.add(s2);
			sensorsInfos.add(s3);
			
			
			while (true) {
				socket = ss.accept();
				System.out.println("The Client has been connectted!");
				new ServerSocketThread(socket,sensorsInfos);
			}
			

		} catch (IOException e) {
			System.out.println("Error: " + e);
			System.exit(1);
		}
		
	}
}
